package com.cz.consume.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Component
public class QueryService {
	
	@LoadBalanced
	@Bean
	RestTemplate restTemplate() {
		return new RestTemplate();
	}
	
	@Autowired
	RestTemplate restTemplate;
	
	
    @HystrixCommand(fallbackMethod="errorConsole")
	public String query(){
		String greeting = this.restTemplate.getForObject("http://service1/", String.class);
		return String.format("%s", greeting);
	}
	
	public String errorConsole(){
		return "error";
	}
}
